home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / Graphic Elements 3 / LibHdrs / Rects.h < prev    next >
Text File  |  1994-05-27  |  2KB  |  102 lines

  1. /*
  2.     Rects.h
  3.     
  4.     Rectangle handling routines for Graphic Elements
  5.     
  6.     Copyright 1993 by Al Evans. All rights reserved.
  7.     
  8.     10/18/93
  9.     
  10. */
  11.  
  12. #ifdef applec
  13. #ifndef __cplusplus
  14. #ifndef PRELOAD
  15. #pragma load "::ToolKit.precompile"
  16. #define PRELOAD
  17. #endif
  18. #endif
  19. #endif
  20.  
  21. #include "List.h"
  22.  
  23. //Entry in a list of rectangles
  24. typedef struct rEntry *RListEntryPtr;
  25.  
  26. typedef struct rEntry {
  27.     RListEntryPtr        nextEntry;
  28.     Rect                thisRect;
  29. } RListEntry;
  30.  
  31. //Coding masks for overlapping rectangles, see CodeRects below
  32. typedef enum {    noOvlp =        0,
  33.                 ovlpTop =         1,
  34.                   ovlpLeft =        1 << 1,
  35.                 ovlpBottom =    1 << 2,
  36.                 ovlpRight =        1 << 3,
  37.                 ovlpTR =        1 << 4,
  38.                 ovlpTL =        1 << 5,
  39.                 ovlpBL =        1 << 6,
  40.                 ovlpBR =        1 << 7,
  41.                 uncoded =        1 << 8
  42.              } RectCode;
  43.  
  44. #ifdef __cplusplus
  45. extern "C" {
  46. #endif
  47.  
  48.  
  49. //Returns a code as defined above showing how testRect overlaps baseRect
  50. RectCode CodeRect(const Rect* testRect, const Rect* baseRect);
  51.  
  52. /*
  53.     The following function is meant to be called iteratively until it returns
  54.     false. If code is non-zero, it returns rectangles in *src2 and *dst2 which
  55.     represent srcRect and dstRect "wrapped around" totalSource. It alters
  56.     the value of code, to reflect the fact that it has handled one case of 
  57.     "wraparound". If code is noOvlp, it clips srcRect against totalSource,
  58.     clips destRect accordingly, and returns the results in src2 and dst2.
  59. */
  60.  
  61. Boolean SplitRects(RectCode *code, const Rect* totalSource, const Rect* srcRect,
  62.         const Rect* dstRect, Rect* src2, Rect* dst2);
  63.  
  64.  
  65. //Rectangle list functions
  66.  
  67. //Returns new rectangle list
  68. LHeaderPtr InitRectList(short nRects);
  69.  
  70. Boolean InsertRectInList(LHeaderPtr listHead, Rect* theRect);
  71.  
  72. //Removes all rectangles from rectList
  73. void ClearRectList( LHeaderPtr rectList);
  74.  
  75. //For convenience
  76.  
  77. short RectHeight(Rect *r);
  78.  
  79. short RectWidth(Rect *r);
  80.  
  81.  
  82. //Fast assembly-language rectangle arithmetic
  83.  
  84. //IFF rects intersect, intersection is returned in rect2
  85. extern Boolean RectsIntersect(const Rect * rect1, Rect * rect2);
  86.  
  87. // rect2 = rect1 U rect2
  88. extern void RectUnion(Rect * rect1, Rect * rect2 );
  89.  
  90. // rect1->top = rect1->left = rect1->bottom = rect1->right = 0
  91. extern void RectZero(Rect * rect1);
  92.  
  93. // true IFF (rect1->top >= rect1->bottom) || (rect1->left >= rect1->right)
  94. extern Boolean RectEmpty(Rect * rect1);
  95.  
  96. // Offsets rect1 by dx, dy
  97. extern void RectOffset(Rect * rect1, long dx, long dy);
  98.  
  99. #ifdef __cplusplus
  100. }
  101. #endif
  102.